package com.spring.hotel.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spring.hotel.common.JsonResponse;
import com.spring.hotel.entity.Checkout;
import com.spring.hotel.entity.PageDTO;
import com.spring.hotel.mapper.CheckoutMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class CheckoutService extends ServiceImpl<CheckoutMapper, Checkout> {
    @Autowired
    private CheckoutMapper checkoutMapper;

    //退房记录
    public JsonResponse insertCheckout(Checkout checkout) {
        checkoutMapper.addCheckout(checkout.getUserid(),String.valueOf(LocalDateTime.now()));
        return JsonResponse.success(null);
    }

    //展示退房记录
    public JsonResponse pageList(Checkout checkout, PageDTO pageDTO) {
        QueryWrapper<Checkout> queryWrapper = new QueryWrapper<>();
        if (checkout.getId() != null) {
            queryWrapper.lambda().like(Checkout::getId, checkout.getId());
        }
        Page<Checkout> page = this.page(new Page<>(pageDTO.getPageNum(), pageDTO.getPageSize()), queryWrapper);
        return JsonResponse.success(page);
    }
}
